// The client represents this user.
PC.Client = Class.create();

Object.extend(PC.Client.prototype, PC.Base.prototype);
Object.extend(PC.Client.prototype, {

  initialize: function() {
    this.initBase();
    this.log("Starting PeerCafe Client...");
    this.peers = $H({});

    // Get a DNS service and figure out our IP.
    //this.dns = Components.classes["@mozilla.org/network/dns-service;1"]
    //  .getService(Components.interfaces.nsIDNSService);
    this.dns = getService("@mozilla.org/network/dns-service;1",
        Components.interfaces.nsIDNSService);

    this.my_addr = this.dns.myHostName;

    this.bootstrap();
  },

  // Connect to the first node to get initial peer list.
  bootstrap: function() {
    this.log("Bootstrapping with master peer...");
    this.master = new PC.MasterPeer(this);
    this.master.requestPeerList(this);
  },

  onStartPeersReceived: function(peer_list) {
		var peer = this;
    this.peer_list = peer_list;
		this.peer_list.each(function(peer_addr) 
				{ 
					peer.log("Addr: " + peer_addr.ip)
				});

    //this.connectToPeers();
  },

  // Start the server socket to accept incoming connections.
  startServer: function() {
    this.server = new CBSConnection();
    this.server.listen(PC_LISTEN_PORT, this)
  },

  // Called on each incoming connection.
  onSocketAccepted: function(socket, transport) {
    this.server.accept(transport, null);

		var peer = new PC.Peer(this);
		peer.setConnection(transport);
		//this.peers[transport.host] = ; 
  }
});

